#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,l,V,d[100005],v[100005],a[100005],p[100005],required_edge[100005];//required edge: first or last which might be required
int main(){
    //>>>DON'T forget to DELETE the // of freopen<<<
    /*silu: tanxin
    a=0: continue
    a>0: conghouwangqian, xiaoyu V continue
    a<0: congqianwanghou, xiaoyu V continue
    zuihou: chaosu cheliang ==0 ze ans zhijie wei m
            chaosu cheliang !=0 ze ans zuiduo wei m-1
    */
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--){
        bool spA=true,spB=true;
        scanf("%d%d%d%d",&n,&m,&l,&V);
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
            if(a[i]!=0) spA=false;
            if(a[i]<=0) spB=false;
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
        }
        sort(p+1,p+m+1);
        int cnt=0,ans=0;
        for(int i=1;i<=n;i++){
            required_edge[i]=0;
        }
        //solve
        if(spA){
            for(int i=1;i<=n;i++){
                if(v[i]>V&&d[i]<=p[m]) cnt++;
            }
            if(cnt) ans=m-1;
            else ans=m;
        }
        else if(spB){
            for(int i=1;i<=n;i++){
                int over_edge;
                if(v[i]>=V) over_edge=d[i];
                else over_edge=d[i]+(V*V-v[i]*v[i])/(2*a[i]);
                if(p[m]<=over_edge) continue;
                int x=upper_bound(p+1,p+m+1,over_edge)-p;
                ans=max(ans,x);
                cnt++;
            }
            if(cnt) ans=m-1;
            else ans=m;
        }
        else{
            for(int i=1;i<=n;i++){
                if(a[i]==0){
                    if(v[i]>V&&d[i]<=p[m]){
                        cnt++;
                        required_edge[i]=d[i];
                    }
                }
                if(a[i]>0){
                    int over_edge;
                    if(v[i]>=V) over_edge=d[i];
                    else over_edge=d[i]+(V*V-v[i]*v[i])/(2*a[i]);//over_edge: kaishi huo jieshu chaosu de dian
                    if(p[m]<=over_edge) continue;
                    int x=upper_bound(p+1,p+m+1,over_edge)-p;
                    required_edge[i]=x;
                    cnt++;
                    //DEBUG, DELETE THE LINE BELOW
                    //printf("%d is overspeed, detected by p[%d]\n",i,x);
                }
                if(a[i]<0){
                    if(v[i]<=V) continue;
                    int over_edge=d[i]+(V*V-v[i]*v[i])/(2*a[i]);
                    if(p[1]>=over_edge) continue;
                    int x=lower_bound(p+1,p+m+1,over_edge)-p;
                    x--;
                    if(p[x]<d[i]) continue;
                    required_edge[i]=x;
                    cnt++;
                    //DEBUG, DELETE THE LINE BELOW
                    //printf("%d is overspeed, detected by p[%d](%d),overedge=%d\n",i,x,p[x],over_edge);
                }
            }
            if(cnt>0){
                int L=m,R=1;//qu liangbian(<L,>R), L qu zuixiaozhi, R qu zuidazhi
                for(int i=1;i<=n;i++){
                    if(required_edge[i]==0) continue;
                    if(a[i]>=0&&required_edge[i]>R) R=required_edge[i];//>0 qu youbian
                    if(a[i]<0&&required_edge[i]<L) L=required_edge[i];//<0 qu zuobian
                }
                if(L>R) ans=m-1;
                else ans=m-2;
            }
            else ans=m;
        }
        printf("%d %d\n",cnt,ans);
    }
    return 0;
}
